#ifndef ZHY_MUDUO_BASE_BLOCKINGQUEUE_H
#define ZHY_MUDUO_BASE_BLOCKINGQUEUE_H

#include "Mutex.h"
#include "Condition.h"

#include <deque>

namespace _zhy_muduo
{
template<typename T>
class BlockingQueue
{
public:
	BlockingQueue()
		: mutex_(),
		notEmpty_(mutex_),
		queue_()
	{}

	void put(const T& x)
	{
		MutexLockGuard lock(mutex_);
		queue_.push_back(x);
		notEmpty_.notify();
	}

	void put(T&& x)
	{
		MutexLockGuard lock(mutex_);
		queue_.push_back(std::move(x));
		notEmpty_.notify();
	}

	T take()
	{
		MutexLockGuard lock(mutex_);
		while (queue_.empty()) {
			notEmpty_.wait();
		}

		T front(std::move(queue_.front()));
		queue_.pop_front();
		return front;
	}

	size_t size() const
	{
		MutexLockGuard lock(mutex_);
		return queue_.size();
	}

	//zhy 
	void clear()
	{
		MutexLockGuard lock(mutex_);
		queue_.clear();
	}
private:
	mutable MutexLock mutex_;
	Condition notEmpty_;
	std::deque<T> queue_;
	BlockingQueue(const BlockingQueue&) = delete;
	BlockingQueue& operator=(const BlockingQueue&) = delete;
};

//TypeName(const TypeName&)=delete;
//TypeName& operator=(const TypeName&)=delete;
	//FIXME:disallow copy assign
	//DISALLOW_COPY_AND_ASSIGN_11(BlockingQueue);
}

#endif // ZHY_MUDUO_BASE_BLOCKINGQUEUE_H
